package com.yonyou.wdt.job;

import cn.hutool.core.map.MapUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.yonyou.wdt.dao.JobLogDao;
import com.yonyou.wdt.entity.OpenApiURLEnum;
import com.yonyou.wdt.entity.QueryDto;
import com.yonyou.wdt.job.config.BaseConfig;
import com.yonyou.wdt.model.JobLogModel;
import com.yonyou.wdt.qimenmodel.qimencloud.api.DefaultQimenCloudClient;
import com.yonyou.wdt.qimenmodel.qimencloud.api.scenehu3cgwt0tc.request.WdtStockinOrderQueryRefundRequest;
import com.yonyou.wdt.qimenmodel.qimencloud.api.scenehu3cgwt0tc.response.WdtStockinOrderQueryRefundResponse;
import com.yonyou.wdt.service.CommonService;
import com.yonyou.wdt.service.YonsuiteService;
import com.yonyou.wdt.utils.DateUtils;
import com.yonyou.wdt.utils.RedisUtils;
import com.yonyou.wdt.utils.WdtConfigProperties;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

@Component
public class WdtQmRefundToYsSaleOut extends BaseConfig {

    private static final Logger logger = LoggerFactory.getLogger(WdtQmRefundToYsSaleOut.class);
    private final WdtConfigProperties configProperties;
    @Resource
    private YonsuiteService yonsuiteService;
    @Resource
    public JobLogDao jobLogDao;
    @Resource
    public CommonService commonService;

    @Autowired
    public WdtQmRefundToYsSaleOut(WdtConfigProperties configProperties) {
        this.configProperties = configProperties;
    }

    @XxlJob("WdtQmRefundToYsJob")
    public ReturnT<String> wdtQmRefundToYsJob(String params) throws Exception {
        String param = XxlJobHelper.getJobParam();
        Map<String, Object> map = new HashMap<>();
        if (param != null && !"".equals(param)) {
            List<String> timeRange = Arrays.asList(param.split("\\|"));
            if (timeRange.size() == 2) {
                map.put("Start", timeRange.get(0));
                map.put("End", timeRange.get(1));
            } else {
                map.put("stockin_no", timeRange.get(0));
            }
        } else {
            // 默认查询前一天的数据
            map.put("Start", DateUtils.getStartDate());
            map.put("End", DateUtils.getEndDate());
        }
        String dateStr = null;
        if (map.get("Start") != null && map.get("End") != null) {
            dateStr = map.get("Start").toString() + map.get("End").toString();
        }

        // 处理相关业务
        QueryDto dto = new QueryDto();
        dto.setTenantId(getYsTenantId());
        dto.setAppKey(getYsAppKey());
        dto.setAppSecret(getYsAppSecret());
        // 获取YS系统租户动态域名信息
        ReturnT<String> isReturn2 = getYsDynamicDomainName(dto);
        // 域名获取失败
        if (isReturn2 != null) return isReturn2;
        try {
            getMerchantList(dto);
            List<JSONObject> responseList = sendWdtByQm(map);
            Integer successCount = 0;
            Integer failCount = 0;
            // 解析数据，组装YS请求参数
            if (!responseList.isEmpty()) {
                ArrayList<Map<String, Object>> ysSaveParamList = new ArrayList<>();
                for (int i = 0; i < responseList.size(); i++) {
                    JSONObject jsonObject = responseList.get(i);
                    //for (JSONObject jsonObject : responseList) {
                    Map<String, Object> ysSaveParam = assembleYsParams(jsonObject, dto);
                    if (ysSaveParam == null) {
                        failCount++;
                        continue;
                    }
                    JSONObject response = yonsuiteService.saleReturnSave(ysSaveParam, dto);
                    String wdtCode = jsonObject.getStr("stockin_no");
                    if (null != response && "200".equals(response.getStr("code"))) {
                        successCount++;
                        logger.info("旺店通销售退货入库单保存YS销售退货成功");
                        InsertLogger(wdtCode, "1", "旺店通销售退货入库单" + wdtCode + "保存YS销售退货" + response.getJSONObject("data").getStr("code") + "成功");
                    } else {
                        failCount++;
                        logger.error("旺店通销售退货入库单保存YS销售退货失败：{}", response.getOrDefault("message", ""));
                        InsertLogger(wdtCode, "0", "旺店通销售退货入库单" + wdtCode + "保存YS销售退货失败" + response.getOrDefault("message", "").toString());
                    }
                    // 处理YS接口调用频率问题
                    // 调用YS接口保存数据
                    this.APICurrentLimiting(OpenApiURLEnum.SALERETURN_SAVE, 19);
                }
                logger.info("当前时间段：{} 需要同步到YS销售退货数据有：{}条", dateStr, responseList.size());
            }
            Thread.sleep(1000);
            InsertLogger(null, "0", "旺店通退货入库一共" + responseList.size() + "条,保存YS销售退货成功:" + successCount + "条，失败:" + failCount + "条。");

        } catch (Exception e) {
            logger.error("Error occurred", e);
            logger.error("旺店通销售退货入库单同步YS销售退货失败，{}", e.getMessage());
            InsertLogger(null, "0", "旺店通销售退货入库单同步YS销售退货失败" + e.getMessage());
            return ReturnT.FAIL;
        }
        logger.info("  --  旺店通销售退货入库单同步YS销售退货任务执行完成  --  ");
        return ReturnT.SUCCESS;
    }

    /**
     * @Author Huangwb
     * @Description 查询YS系统租户动态域名信息
     * @Date 2023/10/30 15:45
     **/
    public ReturnT<String> getYsDynamicDomainName(QueryDto ysQueryDto) {
        try {
            String tenantId = ysQueryDto.getTenantId();  // 租户ID
            if (RedisUtils.get(tenantId + ":DynamicDomainName") == null) {
                // 根据租户ID查询动态域名
                JSONObject dynamicDomainName = yonsuiteService.getDynamicDomainName(null, tenantId);
                if (null != dynamicDomainName && !dynamicDomainName.isEmpty()) {
                    // 将动态域名存入Redis
                    RedisUtils.set(tenantId + ":DynamicDomainName", dynamicDomainName, 86400 * 30);
                } else {
                    logger.error("查询租户【{}】动态域名失败，请重试", tenantId);
                    // insertXxlJobLog(null, "0", "租户：【" + tenantId + "】获取动态域名失败，请稍后重试", jobClassType);
                    InsertLogger(null, "0", "获取动态域名失败");
                    return new ReturnT<>(ReturnT.FAIL_CODE, "查询租户【" + tenantId + "】动态域名失败，请重试");
                }
            }
            // 获取Redis中指定租户动态域名
            JSONObject dynamicDomainNameRedis = (JSONObject) RedisUtils.get(tenantId + ":DynamicDomainName");
            ysQueryDto.setGatewayUrl(dynamicDomainNameRedis.getStr("gatewayUrl"));
            ysQueryDto.setTokenUrl(dynamicDomainNameRedis.getStr("tokenUrl"));
            return null;
        } catch (Exception e) {
            return new ReturnT<>(ReturnT.FAIL_CODE, "获取动态域名失败：" + e.getMessage());
        }
    }

    private void getMerchantList(QueryDto dto) {
        int productPageNo = 1;
        int pageSizeNum = 500;
        try {
            Map<String, Object> map = new HashMap<>();
            map.put("pageIndex", productPageNo);
            map.put("pageSize", pageSizeNum);
            map.put("customerClassCode", "HY020");
            JSONObject customerResult = yonsuiteService.merchantListQuery(map, dto);
            if (customerResult.getStr("code").equals("200")) {
                List data = customerResult.getJSONArray("data");
                for (Object datum : data) {
                    JSONObject entries = JSONUtil.parseObj(datum);
                    String customerName = entries.getJSONObject("name").getStr("simplifiedName");
                    // 将已经存在的客户数据保存至Redis
                    RedisUtils.set("cust:" + dto.getTenantId() + ":" + customerName, entries.getStr("code"), 60 * 60 * 24 * 30);
                }
            }
            this.APICurrentLimiting(OpenApiURLEnum.MERCHANT_LIST_QUERY, 60);
        } catch (Exception e) {
            logger.error("Error occurred", e);
            logger.error("YS客户档案列表查询失败：{}", e.getMessage());
        }

    }

    /**
     * @return
     * @Author Huangwb
     * @Description 组装YS请求数据
     * @Date 14:34 2023/5/17
     * @Param
     **/
    private Map<String, Object> assembleYsParams(JSONObject jsonObject, QueryDto dto) throws Exception {
        Map<String, Object> saleReturnSaveMap = new HashMap<>();
        Map<String, Object> data = new HashMap<>();
        // ==========主表============
        String custName = jsonObject.getStr("fenxiao_nick");
        if (StringUtils.isNotBlank(custName)) {
            Object o = RedisUtils.get("cust:" + dto.getTenantId() + ":" + custName);
            if (o == null) {
                // InsertLogger(null, "0", "旺店通销售出库根据分销商名称查询ys客户档案编码失败，分销商名称:" + custName);
            } else {
                jsonObject.set("shop_no", o);
            }
        }
        // 添加表头
        String custCode = jsonObject.getStr("shop_no");
        String orgCode = "30";
        saleReturnSaveMap.put("corpContact", "00000104");  // 销售业务员，传id或者code
        //saleReturnSaveMap.put("resubmitCheckKey", saleOutCode + "20230818");  // 幂等性
        saleReturnSaveMap.put("salesOrgId", orgCode);  // 销售组织
        String refundNo = jsonObject.getStr("stockin_no");
        saleReturnSaveMap.put("code", refundNo);  // 单据编号
        saleReturnSaveMap.put("agentId", custCode);  // 客户
        saleReturnSaveMap.put("transactionTypeId", "RET001");  // 交易类型
        //saleReturnSaveMap.put("bizFlow", bizFlow);  // 流程ID （2C）
        // 单据日期-修改时间
	/*	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		String modified = format.format(jsonObject.getStr("modified"));*/
        saleReturnSaveMap.put("vouchdate", jsonObject.getStr("created_time"));  // 单据日期
        saleReturnSaveMap.put("settlementOrgId", orgCode);  // 开票组织
        saleReturnSaveMap.put("currency", "CNY");  // 币种
        saleReturnSaveMap.put("exchangeRateType", "01");  // 汇率类型
        saleReturnSaveMap.put("natCurrency", "CNY");  // 本币
        saleReturnSaveMap.put("exchRate", 1);  // 汇率
        saleReturnSaveMap.put("taxInclusive", true);  // 单价含税
        saleReturnSaveMap.put("saleReturnSourceType", "NONE");  // 退货类型
        saleReturnSaveMap.put("invoiceAgentId", custCode);  // 开票客户
        saleReturnSaveMap.put("_status", "Insert");  // 操作标识

        // 获取Redis中客户档案信息
        JSONObject custPrJson = (JSONObject) RedisUtils.get(dto.getTenantId() + ":cust:" + custCode);
        if (custPrJson == null) {
            // 保存同步错误日志，未找到对应物料档案信息
            logger.error("存在未同步YS系统客户数据：{}，请同步后重试", custCode);
            InsertLogger(refundNo, "0", "存在未同步YS系统客户数据：" + custCode + "，请同步后重试");
            return null;
        }

        JSONArray items = jsonObject.getJSONArray("details_list");
        // ==========子表============
        JSONArray details = new JSONArray();
        BigDecimal payMoney = BigDecimal.ZERO;
        for (Object element : items) {
            JSONObject item = (JSONObject) element;
            // 获取物料编码
            String product = item.getStr("goods_no");
            String suiteNo = item.getStr("suite_no");
            // 获取Redis中物料档案信息
            JSONObject redisPrJson = (JSONObject) RedisUtils.get(dto.getTenantId() + ":product:" + product);
            if (redisPrJson == null) {
                // 保存同步错误日志，未找到对应物料档案信息
                commonService.proToRedis(product, dto);
                redisPrJson = (JSONObject) RedisUtils.get(dto.getTenantId() + ":product:" + product);
                if (redisPrJson == null) {
                    logger.error("存在未同步YS系统物料数据：{}，请同步后重试", product);
                    InsertLogger(refundNo, "0", "存在未同步YS系统物料数据：" + product + "，请同步后重试");
                    return null;
                }
            }
            String unitId = redisPrJson.getStr("unitId") != null ? redisPrJson.getStr("unitId") : null;
            if (unitId == null) {
                logger.error("售后单：" + refundNo + "存在未维护单位物料，请维护后重试");
                InsertLogger(refundNo, "0", "存在未维护单位物料，请维护后重试");
            }
            // ===========子表============
            // 添加表体数据
            JSONObject saleReturnDetailsJson = new JSONObject();
            saleReturnDetailsJson.put("productId", product);  // 商品，传id或者code
            saleReturnDetailsJson.put("skuId", product);  // 商品SKU，传id或者code
            saleReturnDetailsJson.put("unitExchangeType", 1);  // 浮动换算率（销售）int
            saleReturnDetailsJson.put("unitExchangeTypePrice", 1);  // 浮动换算率（计价）int
            saleReturnDetailsJson.put("taxId", redisPrJson.getStr("outTaxrate") != null ? redisPrJson.getStr("outTaxrate") : "TE");  // 税目税率，);  // 税目税率，传id或者code

            JSONObject entries = commonService.priceListQuery(orgCode, saleReturnSaveMap.get("vouchdate").toString(), dto);
            BigDecimal price = new BigDecimal(0.01).setScale(2, BigDecimal.ROUND_HALF_UP);
            if ("200".equals(entries.getStr("code"))) {
                JSONArray priceData = entries.getJSONArray("data");
                JSONObject pricingRecordJson = new JSONObject();
                String customerLevelId = custPrJson.getStr("customerLevelId");
                if (!priceData.isEmpty() && StringUtils.isNotBlank(customerLevelId)) {
                    for (Object datum : priceData) {
                        JSONObject datumJson = (JSONObject) datum;
                        if (datumJson.getStr("productId_code").equals(product) && customerLevelId.equals(datumJson.getStr("dimension_agentLevelId"))) {
                            pricingRecordJson = datumJson;
                            break;
                        }
                    }
                    // 存在调价单
                    if (pricingRecordJson.getBigDecimal("adjustGradients_price") != null) {
                        // 调价单维护了价格，价格取调价单金额
                        // 获取成本价
                        price = pricingRecordJson.getBigDecimal("adjustGradients_price");
                    }
                }
            } else {
                logger.error("查询价格表失败：{}", entries.getStr("message"));
                InsertLogger(saleReturnSaveMap.get("code").toString(), "0", "查询价格表失败：" + entries.getStr("message"));
                return null;
            }

            BigDecimal saleAmount = BigDecimal.ZERO;
            BigDecimal outTaxrate;
            BigDecimal unitPriceIncludingTax = BigDecimal.ZERO;
            BigDecimal taxAmount = BigDecimal.ZERO;
            BigDecimal noTaxSaleAmount = BigDecimal.ZERO;
            BigDecimal taxFreeUnitPrice = BigDecimal.ZERO;
            BigDecimal qty = item.getBigDecimal("goods_count");
            // 金额计算：

            // 金额
            saleAmount = qty.multiply(price).setScale(2, RoundingMode.HALF_UP);
            payMoney.add(saleAmount);
            // 税率
            outTaxrate = redisPrJson.containsKey("outTaxrate_name") ? redisPrJson.getBigDecimal("outTaxrate_name") : BigDecimal.ZERO;
            // 含税单价
            unitPriceIncludingTax = saleAmount.divide(qty, 4, RoundingMode.HALF_UP);
            // 税额
            if (!"0".equals(outTaxrate.toString())) {
                taxAmount = saleAmount.divide(outTaxrate.divide(new BigDecimal(100)).add(new BigDecimal(1)), 4, RoundingMode.HALF_UP).multiply(outTaxrate.divide(new BigDecimal(100), 4, RoundingMode.HALF_UP)).setScale(2, RoundingMode.HALF_UP);
                // taxAmount = saleAmount.multiply(outTaxrate.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP));
            }
            // 无税金额
            noTaxSaleAmount = saleAmount.subtract(taxAmount);
            // 无税单价
            taxFreeUnitPrice = noTaxSaleAmount.divide(BigDecimal.valueOf(Double.parseDouble(String.valueOf(qty))), 4, RoundingMode.HALF_UP);

            saleReturnDetailsJson.put("stockId", jsonObject.getStr("warehouse_no"));  // 仓库
            saleReturnDetailsJson.put("stockOrgId", orgCode);  // 库存组织，传id或者code
            saleReturnDetailsJson.put("iProductAuxUnitId", unitId);  // 销售单位，传id或者code
            saleReturnDetailsJson.put("iProductUnitId", unitId);  // 计价单位，传id或者code
            saleReturnDetailsJson.put("masterUnitId", unitId);  // 主计量单位，传id或者code
            saleReturnDetailsJson.put("invExchRate", 1);  // 销售换算率 BigDecimal
            saleReturnDetailsJson.put("subQty", qty);  // 退货销售数量 BigDecimal
            saleReturnDetailsJson.put("invPriceExchRate", 1);  // 计价换算率 BigDecimal
            saleReturnDetailsJson.put("priceQty", qty);  // 退货计价数量 BigDecimal
            saleReturnDetailsJson.put("qty", qty);  // 退货数量 BigDecimal
            saleReturnDetailsJson.put("oriTaxUnitPrice", unitPriceIncludingTax);  // 含税成交价 BigDecimal
            saleReturnDetailsJson.put("oriUnitPrice", taxFreeUnitPrice);  // 无税单价  BigDecimal
            saleReturnDetailsJson.put("oriSum", saleAmount);  // 含税金额  BigDecimal
            saleReturnDetailsJson.put("oriMoney", noTaxSaleAmount);  // 无税金额  BigDecimal
            saleReturnDetailsJson.put("oriTax", taxAmount);  // 税额  BigDecimal
            saleReturnDetailsJson.put("natTaxUnitPrice", unitPriceIncludingTax);  // 本币含税单价  BigDecimal
            saleReturnDetailsJson.put("natUnitPrice", taxFreeUnitPrice);  // 本币无税单价  BigDecimal
            saleReturnDetailsJson.put("natSum", saleAmount);  // 本币含税金额  BigDecimal
            saleReturnDetailsJson.put("natMoney", noTaxSaleAmount);  // 本币无税金额  BigDecimal
            saleReturnDetailsJson.put("natTax", taxAmount);  // 本币税额  BigDecimal
            saleReturnDetailsJson.put("_status", "Insert");  // 操作标识
            //调用销售保存接口时，子表为PTO母件商品行需要加个字段 "virtualProductAttribute":16
           /* if (StringUtils.isNotBlank(suiteNo)) {
                HashMap<String, Object> detailDefMap = new HashMap<>();
                Object o = RedisUtils.get(dto.getTenantId() + ":bom:" + suiteNo);
                if (o == null) {
                    InsertLogger(null, "0", "存在未同步YS系统物料清单数据：" + suiteNo + "，请同步后重试");
                    return null;
                }
                List<JSONObject> list = JSONUtil.toList(o.toString(), JSONObject.class);
                BigDecimal newQty = BigDecimal.ZERO;
                for (JSONObject object : list) {
                    JSONObject entries1 = JSONUtil.parseObj(object);
                    if (product.equals(entries1.getStr("bomComponent_productCode"))) {
                        newQty = qty.divide(entries1.getBigDecimal("bomComponent_stockQuantity"), 4, BigDecimal.ROUND_HALF_UP);
                        break;
                    }
                }
                detailDefMap.put("E_05", newQty);
                detailDefMap.put("E_03", jsonObject.getStr("tid"));
                detailDefMap.put("E_02", suiteNo);
                saleReturnDetailsJson.put("saleReturnDetailDefineCharacter", detailDefMap);
            }*/
            saleReturnDetailsJson.put("batchNo", "旺店通");  // 批次号
            details.add(saleReturnDetailsJson);
        }
        saleReturnSaveMap.put("saleReturnDetails", details);
        saleReturnSaveMap.put("payMoney", payMoney);
        saleReturnSaveMap.put("resubmitCheckKey", UUID.randomUUID().toString().replace("-", ""));
        data.put("data", saleReturnSaveMap);
        //ReSubmitUtil.resubmitCheckKey(data);
        return data;
    }

    /**
     * @return
     * @Author Huangwb
     * @Description 插入数据库日志信息
     * @Date 10:30 2023/9/14
     * @Param
     **/
    private void InsertLogger(String code, String oneL, String mags) {  // 单据编号、是否成功、详细信息
        try {
            JobLogModel jobLogDTO = new JobLogModel();
            jobLogDTO.setJobClass("HYZM008");
            jobLogDTO.setJobCode(code);
            jobLogDTO.setJobTime(new Date());
            jobLogDTO.setJobResult(oneL);
            jobLogDTO.setJobResultMessage(mags);
            jobLogDTO.setJobLogUser("dxroot");
            jobLogDao.insertJobLog(jobLogDTO);
        } catch (Exception e) {
            logger.error("插入日志错误：" + e.getMessage());
        }
    }


    private List<JSONObject> sendWdtByQm(Map<String, Object> map) {
        List<JSONObject> resList = new ArrayList<>();
        DefaultQimenCloudClient client = new DefaultQimenCloudClient(configProperties.getQmServerUrl(), configProperties.getQmAppKey(), configProperties.getQmAppSecret(), "json");
        Integer realityPageNo = 0;
        map.put("page_no", realityPageNo.toString());
        map.put("page_size", "100");
        boolean hasNext = true;
        //总页数
        Integer totalPage = 0;
        //总条数
        Integer total_count = 0;
        while (hasNext) {
            map.put("page_no", realityPageNo.toString());
            WdtStockinOrderQueryRefundRequest req = this.setModel(map, configProperties.getQmTargetAppKey(), configProperties.getSid());
            WdtStockinOrderQueryRefundResponse res = null;
            try {
                res = client.execute(req);
            } catch (com.yonyou.wdt.qimenmodel.taobao.api.ApiException e) {
                throw new RuntimeException(e);
            }
            JSONObject saleOutJson = JSONUtil.parseObj(res.getBody()).getJSONObject("response");
            if ("0".equals(saleOutJson.getStr("errorcode"))) {
                //判断分页
                if (realityPageNo == 0) {
                    total_count = saleOutJson.getInt("total_count", 0);
                    totalPage = total_count % 100 == 0 ? total_count / 100 : total_count / 100 + 1;
                }
                //每页订单列表
                JSONArray orderArray = saleOutJson.getJSONArray("stockin_list");
                if (orderArray.size() > 0) {
                    resList.addAll(JSONUtil.toList(orderArray, JSONObject.class));
                }
                //判断分页
                if (realityPageNo == 0) {
                    total_count = saleOutJson.getInt("total_count", 0);
                    totalPage = total_count % 100 == 0 ? total_count / 100 : total_count / 100 + 1;
                }
                if (totalPage > realityPageNo + 1) {
                    realityPageNo += 1;
                } else {
                    hasNext = false;
                }
            } else {
                InsertLogger(null, "0", "旺店通退货入库接口查询失败" + saleOutJson.getStr("message"));
                break;
            }
        }
        // resList = resList.stream().filter(o -> !"4".equals(o.getStr("type"))).collect(Collectors.toList());
        return resList;
    }

    public WdtStockinOrderQueryRefundRequest setModel(Map param, String targetAppKey, String sid) {
        WdtStockinOrderQueryRefundRequest req = new WdtStockinOrderQueryRefundRequest();
        //旺店通的奇门appkey
        req.setTargetAppKey(targetAppKey);
        //旺店通erp的卖家账号
        req.setSid(sid);
        String startTime = MapUtil.getStr(param, "Start");
        if (StringUtils.isNotBlank(startTime)) {
            req.setStartTime(startTime);
        }
        String endTime = MapUtil.getStr(param, "End");
        if (StringUtils.isNotBlank(endTime)) {
            req.setEndTime(endTime);
        }
        String stockinNo = MapUtil.getStr(param, "stockin_no");
        if (StringUtils.isNotBlank(stockinNo)) {
            req.setStockinNo(stockinNo);
        }
        String srcOrderNo = MapUtil.getStr(param, "src_order_no");
        if (StringUtils.isNotBlank(srcOrderNo)) {
            req.setSrcOrderNo(srcOrderNo);
        }
        String shop_no = MapUtil.getStr(param, "shop_no");
        if (StringUtils.isNotBlank(shop_no)) {
            req.setShopNo(shop_no);
        }
        if (param.containsKey("page_no")) {
            req.setPageNo(MapUtil.getLong(param, "page_no"));
        }
        if (param.containsKey("page_size")) {
            req.setPageSize(MapUtil.getLong(param, "page_size"));
        }
        if (param.containsKey("status")) {
            req.setStatus(MapUtil.getLong(param, "status"));
        }
        if (param.containsKey("shop_nos")) {
            req.setShopNos(MapUtil.getStr(param, "shop_nos"));
        }
        return req;
    }
}
